//
//  RootViewController.m
//  HW1-1
//
//  Created by dllo on 15/11/9.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "RootViewController.h"

@interface RootViewController ()

@property (nonatomic, retain) NSArray *colorArr;

@end

@implementation RootViewController

- (void)dealloc
{
    [_colorArr release];
    [super dealloc];
}



- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.colorArr = [NSArray arrayWithObjects:[UIColor redColor], [UIColor grayColor], [UIColor purpleColor], [UIColor yellowColor], [UIColor orangeColor], [UIColor blueColor], [UIColor cyanColor], nil];
    
    for (NSInteger i = 0; i < 7; i++) {
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(30 * i, 30 * i, self.view.frame.size.width - 60 * i, self.view.frame.size.height - 60 * i)];
        view.backgroundColor = [self.colorArr objectAtIndex:i];
        [self.view addSubview:view];
        [view release];
        
    }
    
    [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(colorAction) userInfo:nil repeats:YES];
 
}


- (void)colorAction
{
    
    // 遍历子视图数组
    for (UIView *view in self.view.subviews) {
        
        // 将当前视图的颜色赋给下一个视图
        // 获取当前视图颜色在颜色数组的下标
        NSUInteger index = [self.colorArr indexOfObject:view.backgroundColor];
        
        // 传递颜色, 注意越界
        view.backgroundColor = [self.colorArr objectAtIndex:(index +1) % 7];
        
    }
}








- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
